package fun.formoji.alg.api.fallback;


import feign.hystrix.FallbackFactory;
import fun.formoji.alg.api.BaseDataApi;
import fun.formoji.alg.resp.BrandPreferenceVO;
import fun.formoji.alg.resp.IdInfoVo;
import fun.formoji.alg.resp.UserLowLoyaltyCategoryVO;
import fun.formoji.alg.resp.UserObItemCategoryVO;
import fun.formoji.commons.model.RestResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author h
 * @date 2021/2/3 16:15
 * @description
 */
@Slf4j
@Component
public class BaseDataApiFallBackFactory implements FallbackFactory<BaseDataApi> {
    @Override
    public BaseDataApi create(Throwable cause) {
        log.error("Failed to call {},reason:{}", BaseDataApi.class.getName(),cause.getMessage(), cause);

        return new BaseDataApi() {
            @Override
            public RestResponse<IdInfoVo> idInfo(String idType, String idValue) {
                return RestResponse.fallback();
            }

            @Override
            public RestResponse<BrandPreferenceVO> brandPreference(String userId) {
                return RestResponse.fallback();
            }

            @Override
            public RestResponse<UserLowLoyaltyCategoryVO> userLowLoyaltyCategory(String userId) {
                return RestResponse.fallback();
            }

            @Override
            public RestResponse<UserObItemCategoryVO> userObItemCategory(String userId) {
                return RestResponse.fallback();
            }
        };
    }
}
